package com.smartleanx.module.hrm.controller.admin.examine.examineRangeType;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.smartleanx.framework.common.pojo.PageParam;
import com.smartleanx.framework.common.pojo.PageResult;
import com.smartleanx.framework.common.pojo.CommonResult;
import com.smartleanx.framework.common.util.object.BeanUtils;
import static com.smartleanx.framework.common.pojo.CommonResult.success;

import com.smartleanx.framework.excel.core.util.ExcelUtils;

import com.smartleanx.framework.operatelog.core.annotations.OperateLog;
import static com.smartleanx.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.smartleanx.module.hrm.controller.admin.examine.examineRangeType.vo.*;
import com.smartleanx.module.hrm.dal.dataobject.examine.examineRangeType.ExamineRangeTypeDO;
import com.smartleanx.module.hrm.service.examine.examineRangeType.ExamineRangeTypeService;

@Tag(name = "管理后台 - 审核	范围")
@RestController
@RequestMapping("/hrm/examine-range-type")
@Validated
public class ExamineRangeTypeController {

    @Resource
    private ExamineRangeTypeService examineRangeTypeService;

    @PostMapping("/create")
    @Operation(summary = "创建审核	范围")
    @PreAuthorize("@ss.hasPermission('hrm:examine-range-type:create')")
    public CommonResult<Integer> createExamineRangeType(@Valid @RequestBody ExamineRangeTypeSaveReqVO createReqVO) {
        return success(examineRangeTypeService.createExamineRangeType(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新审核	范围")
    @PreAuthorize("@ss.hasPermission('hrm:examine-range-type:update')")
    public CommonResult<Boolean> updateExamineRangeType(@Valid @RequestBody ExamineRangeTypeSaveReqVO updateReqVO) {
        examineRangeTypeService.updateExamineRangeType(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除审核	范围")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('hrm:examine-range-type:delete')")
    public CommonResult<Boolean> deleteExamineRangeType(@RequestParam("id") Integer id) {
        examineRangeTypeService.deleteExamineRangeType(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得审核	范围")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('hrm:examine-range-type:query')")
    public CommonResult<ExamineRangeTypeRespVO> getExamineRangeType(@RequestParam("id") Integer id) {
        ExamineRangeTypeDO examineRangeType = examineRangeTypeService.getExamineRangeType(id);
        return success(BeanUtils.toBean(examineRangeType, ExamineRangeTypeRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得审核	范围分页")
    @PreAuthorize("@ss.hasPermission('hrm:examine-range-type:query')")
    public CommonResult<PageResult<ExamineRangeTypeRespVO>> getExamineRangeTypePage(@Valid ExamineRangeTypePageReqVO pageReqVO) {
        PageResult<ExamineRangeTypeDO> pageResult = examineRangeTypeService.getExamineRangeTypePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ExamineRangeTypeRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出审核	范围 Excel")
    @PreAuthorize("@ss.hasPermission('hrm:examine-range-type:export')")
    @OperateLog(type = EXPORT)
    public void exportExamineRangeTypeExcel(@Valid ExamineRangeTypePageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ExamineRangeTypeDO> list = examineRangeTypeService.getExamineRangeTypePage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "审核	范围.xlsx", "数据", ExamineRangeTypeRespVO.class,
                        BeanUtils.toBean(list, ExamineRangeTypeRespVO.class));
    }

}